<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        #box {
            width: 100px;
            height: 100px;
            background-color: blue;
        }
        
        body {
            height: 2000px;
        }
    </style>
</head>

<body>
    <div class="" id="box"></div>
    <h1 id="info">0</h1>
    <script>
        var oBox = document.getElementById("box");
        var oInfo = document.getElementById("info");
        // 全局变量就是info中显示的数字
        var a = 0;
        // 给box添加鼠标滚轮事件监听
        oBox.onmousewheel = function(e) {
            // 阻止默认事件：就是说当用户在盒子里面滚动鼠标滚的时候，此时不会引发滚动条的滚动
            e.preventDefault();
            if (e.deltaY > 0) {
                a++;
            } else {
                a--;
            }
            oInfo.innerText = a;
        };
    </script>
</body>

</html>